package com.ruoyi.tb.lmt.service.scheduler;

import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.tb.lmt.domain.*;
import com.ruoyi.tb.lmt.domain.bo.*;
import com.ruoyi.tb.lmt.domain.vo.*;
import com.ruoyi.tb.lmt.mapper.TbLmtrepairWorkdetailMapper;
import com.ruoyi.tb.lmt.mapper.TbWheelDiameterMapper;
import com.ruoyi.tb.lmt.service.*;
import com.ruoyi.tb.lmt.service.impl.TbRepairplanlistServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

@Component
public class SchedulerTask {

    @Autowired
    private ITbMessageNoticeService tbMessageNoticeService;

    @Autowired
    private TbLmtrepairWorkdetailMapper tbLmtrepairWorkdetailMapper;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    ISytDataService sytDataService;

    @Autowired
    IMcgsFpfzService imcgsFpfzService;

    @Autowired
    IMcgsZjfzService imcgsZjfzService;

    @Autowired
    IMcgsXzzService imcgsXzzService;

    @Autowired
    IMcgsXzz1Service imcgsXzz1Service;

    @Autowired
    IMcgsJjf1zService imcgsJjf1zService;

    @Autowired
    IMcgsZdfzService iMcgsZdfzService;

    @Autowired
    ITbLmtrepairWorkdetailService iTbLmtrepairWorkdetailService;

    @Autowired
    IDrDamperDataService iDrDamperDataService;

    @Autowired
    IOilSampleDetectionService iOilSampleDetectionService;

    //每天晚上11点半点执行一次任务提醒
    @Scheduled(cron = "0 30 23 * * ?")
    //@Scheduled(cron = "*/20 * * * * *")
    public void run() throws ParseException {
        // 创建一个Calendar实例
        Calendar calendar = Calendar.getInstance();

        // 将时间设置为当前时间
        calendar.setTime(new Date());

        // 减去一天来设置日期为前一天
        calendar.add(Calendar.DATE, -1);

        // 设置时分秒为午夜00:00:00
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 从Calendar实例获取修改后的时间
        Date startRequireDate = calendar.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 1. 执行 SQL 查询
        List<TbLmtrepairWorkdetailVo> result = tbLmtrepairWorkdetailMapper.selectMessageUser(startRequireDate);

        // 2. 准备集合以跟踪不同的 workUser 和 workGroup
        Set<String> uniqueWorkUsers = new HashSet<>();
        Set<String> uniqueWorkGroups = new HashSet<>();

        // 遍历结果集
        for (TbLmtrepairWorkdetailVo item : result) {
            String workUser = item.getWorkUser();
            String workGroup = item.getWorkGroup();

            if (workUser != null) {
                // 收集不同的 workUser
                uniqueWorkUsers.add(workUser);
            }
            if (workGroup != null) {
                // 对于 workUser 为 null 的条目，收集不同的 workGroup
                uniqueWorkGroups.add(workGroup);
            }
        }

        // 3. 为每个不同的 workUser 创建消息通知
        for (String workUser : uniqueWorkUsers) {
            String count = tbLmtrepairWorkdetailMapper.selectMessageCount(workUser, startRequireDate);
            TbMessageNoticeBo bo = new TbMessageNoticeBo();
            bo.setWorkGroup("系统管理员");
            bo.setWorkGroupId(103L);
            bo.setStatus("0");
            bo.setWorkUser("admin");
            bo.setWorkTime(new Date());
            bo.setCreateBy("admin");
            bo.setCreateTime(new Date());
            bo.setMessageTitle("任务超时提醒");
            bo.setMessageType("任务提醒");
            bo.setRecipient(workUser);
            bo.setMessageName("有" + count + "条任务未完成,点击详情查看自己是否有未完成任务,请及时处理。");
            // 插入消息通知
            tbMessageNoticeService.insertByBo(bo);
        }

        // 4. 对于 workUser 为 null 的情况，处理 workGroup
        for (String workGroup : uniqueWorkGroups) {
            // 基于 workGroup 找到对应的组长 workUser
            String groupLeader = tbLmtrepairWorkdetailMapper.findGroupLeaderByWorkGroup(workGroup);

            if (groupLeader != null) {
                String count = tbLmtrepairWorkdetailMapper.selectMessageCountByGroup(workGroup, startRequireDate);

                TbMessageNoticeBo bo = new TbMessageNoticeBo();
                bo.setWorkGroup("系统管理员");
                bo.setWorkGroupId(103L);
                bo.setStatus("0");
                bo.setWorkUser("admin");
                bo.setWorkTime(new Date());
                bo.setCreateBy("admin");
                bo.setCreateTime(new Date());
                bo.setMessageTitle("任务超时提醒");
                bo.setMessageType("任务提醒");
                bo.setRecipient(groupLeader); // 设置为组长
                bo.setMessageName("共有" + count + "条任务未完成,点击详情查看组员是否有未完成任务,请及时处理。");
                // 插入消息通知
                tbMessageNoticeService.insertByBo(bo);
            }
        }

    }

    //每天下午4点执行一次定时任务
    @Scheduled(cron = "0 0 16 * * ?")
    //@Scheduled(cron = "*/20 * * * * *")
    public void run2() throws ParseException {
        // 查询所有状态为"正式计划"的计划
        List<Map<String, Object>> plans = jdbcTemplate.queryForList(
            "SELECT * FROM tb_repairplan WHERE status = '正式计划'"
        );

        // 遍历每个计划
        for (Map<String, Object> plan : plans) {
            Long planId = (Long) plan.get("id");

            // 查询该计划下的所有任务
            List<Map<String, Object>> tasks = jdbcTemplate.queryForList(
                "SELECT t1.*, t2.status as planStatus FROM tb_repairplanlist t1 " +
                    "LEFT JOIN tb_repairplan t2 ON t1.plan_ID = t2.id " +
                    "WHERE t2.id = ?",
                planId
            );

            // 检查是否所有任务都已完成
            boolean allTasksCompleted = tasks.stream()
                .allMatch(task -> "已完成".equals(task.get("status")));

            // 如果所有任务都已完成，则更新计划状态为"已完成"
            if (allTasksCompleted) {
                jdbcTemplate.update(
                    "UPDATE tb_repairplan SET status = '已完成' WHERE id = ?",
                    planId
                );
            }
        }
    }

    //调用试验台同步数据
    @Scheduled(cron = "0 0 12 * * ?")
    //@Scheduled(cron = "*/20 * * * * *")
    public void run3() throws ParseException, FileNotFoundException, JsonProcessingException {
        sytDataService.readExcel();
        sytDataService.execSytJob();
    }

    /**
     * 自动生成检修计划
     *
     * @throws Exception
     */
    @Autowired
    private ITbLmttypeService tbLmttypeService;

    @Autowired
    private ITbLocomotiveService tbLocomotiveService;

    @Autowired
    private ITbRepairplanService tbRepairplanService;


    @Autowired
    private TbWheelDiameterMapper tbWheelDiameterMapper;

    public void queryAllRepairTimeCreateWorkDetail() throws Exception {
        List<TbLmtTypeRepairTimeVo> times = tbLmttypeService.queryAllRepairTimeList();
        Date nowDate = DateUtils.getNowDate();
        for (TbLmtTypeRepairTimeVo type : times) {
            //查询当前车型的车号
            List<TbRepairplanlistBo> repairplanlistBos = new ArrayList<>();
            TbLocomotiveBo bo = new TbLocomotiveBo();
            bo.setLmtType(type.getLmtType());
            List<TbLocomotiveVo> tbLocomotiveVos = tbLocomotiveService.queryList(bo);
            for (TbLocomotiveVo tbLocomotiveVo : tbLocomotiveVos) {
                if (type.getFourRepairTime() != null && 0 != type.getFourRepairTime()) {
                    //执行查询最近一次四级修
                    TbLmtrepairWorkdetailVo tbLmtrepairWorkdetailVo = iTbLmtrepairWorkdetailService.selectTopOneByLmtNumberAndRepairChar(tbLocomotiveVo.getLmtNumber(), "四级修");
                    if (tbLmtrepairWorkdetailVo != null) {
                        if (tbLmtrepairWorkdetailVo.getStartTime() != null) {
                            int dayNum = DateUtils.differentDaysByMillisecond(tbLmtrepairWorkdetailVo.getStartTime(), nowDate);
                            if (dayNum >= type.getFourRepairTime()) {
                                //为当前车辆新建计划（添加到计划中）
                                PageQuery pageQuery = new PageQuery();
                                pageQuery.setPageNum(1);
                                pageQuery.setPageSize(1);
                                TableDataInfo<TbLocomotiveVo> tbLocomotiveVoTable = tbLocomotiveService.lmtListByStatus(bo, pageQuery);
                                if (tbLocomotiveVoTable != null) {
                                    List<TbLocomotiveVo> rows = tbLocomotiveVoTable.getRows();
                                    if (rows != null && rows.size() > 0) {
                                        TbRepairplanlistBo repairplanlistBo = BeanUtil.toBean(rows.get(0), TbRepairplanlistBo.class);
                                        repairplanlistBo.setId(null);
                                        repairplanlistBo.setRepairType("四级修");
                                        repairplanlistBos.add(repairplanlistBo);
                                    }
                                }
                            }
                        }
                    }
                }
                if (type.getThreeRepairTime() != null && 0 != type.getThreeRepairTime()) {
                    //查询最近一次三级修
                    TbLmtrepairWorkdetailVo tbLmtrepairWorkdetailVo = iTbLmtrepairWorkdetailService.selectTopOneByLmtNumberAndRepairChar(tbLocomotiveVo.getLmtNumber(), "三级修");
                    if (tbLmtrepairWorkdetailVo != null) {
                        if (tbLmtrepairWorkdetailVo.getStartTime() != null) {
                            int dayNum = DateUtils.differentDaysByMillisecond(tbLmtrepairWorkdetailVo.getStartTime(), nowDate);
                            if (dayNum >= type.getThreeRepairTime()) {
                                //为当前车辆新建计划（添加到计划中）
                                PageQuery pageQuery = new PageQuery();
                                pageQuery.setPageNum(1);
                                pageQuery.setPageSize(1);
                                TableDataInfo<TbLocomotiveVo> tbLocomotiveVoTable = tbLocomotiveService.lmtListByStatus(bo, pageQuery);
                                if (tbLocomotiveVoTable != null) {
                                    List<TbLocomotiveVo> rows = tbLocomotiveVoTable.getRows();
                                    if (rows != null && rows.size() > 0) {
                                        TbRepairplanlistBo repairplanlistBo = BeanUtil.toBean(rows.get(0), TbRepairplanlistBo.class);
                                        repairplanlistBo.setId(null);
                                        repairplanlistBo.setRepairType("三级修");
                                        repairplanlistBos.add(repairplanlistBo);
                                    }
                                }
                            }
                        }
                    }
                }
                if (type.getTwoRepairTime() != null && 0 != type.getTwoRepairTime()) {
                    //查询最近一次二级修
                    TbLmtrepairWorkdetailVo tbLmtrepairWorkdetailVo = iTbLmtrepairWorkdetailService.selectTopOneByLmtNumberAndRepairChar(tbLocomotiveVo.getLmtNumber(), "二级修");
                    if (tbLmtrepairWorkdetailVo != null) {
                        if (tbLmtrepairWorkdetailVo.getStartTime() != null) {
                            int dayNum = DateUtils.differentDaysByMillisecond(tbLmtrepairWorkdetailVo.getStartTime(), nowDate);
                            if (dayNum >= type.getTwoRepairTime()) {
                                //为当前车辆新建计划（添加到计划中）
                                PageQuery pageQuery = new PageQuery();
                                pageQuery.setPageNum(1);
                                pageQuery.setPageSize(1);
                                TableDataInfo<TbLocomotiveVo> tbLocomotiveVoTable = tbLocomotiveService.lmtListByStatus(bo, pageQuery);
                                if (tbLocomotiveVoTable != null) {
                                    List<TbLocomotiveVo> rows = tbLocomotiveVoTable.getRows();
                                    if (rows != null && rows.size() > 0) {
                                        TbRepairplanlistBo repairplanlistBo = BeanUtil.toBean(rows.get(0), TbRepairplanlistBo.class);
                                        repairplanlistBo.setId(null);
                                        repairplanlistBo.setRepairType("二级修");
                                        repairplanlistBos.add(repairplanlistBo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            System.out.println(type.getLmtType());
            if (repairplanlistBos != null && repairplanlistBos.size() > 0) {
                TbRepairplanBo repairplanBo = new TbRepairplanBo();
                repairplanBo.setStatus("预计划");
                repairplanBo.setPlanName(DateUtils.getDate() + " " + type.getLmtType() + " 系统生成计划");
                repairplanBo.setPlanDate(nowDate);
                repairplanBo.setRepairplanlistVos(repairplanlistBos);
                //TODO 生成预计划
                //tbRepairplanService.insertPlanAndListByBo(repairplanBo);
            }
        }
    }


    public void test() {
        List<TbLmtTypeRepairTimeVo> times = tbLmttypeService.queryAllRepairTimeList();
        Date nowDate = DateUtils.getNowDate();
        for (TbLmtTypeRepairTimeVo type : times) {
            //查询当前车型的车号
            List<TbRepairplanlistBo> repairplanlistBos = new ArrayList<>();
            TbLocomotiveBo bo = new TbLocomotiveBo();
            bo.setLmtType(type.getLmtType());
            List<TbLocomotiveVo> tbLocomotiveVos = tbLocomotiveService.queryList(bo);
            for (TbLocomotiveVo tbLocomotiveVo : tbLocomotiveVos) {
                //查询最近一次二级修
                TbLmtrepairWorkdetailVo tbLmtrepairWorkdetailVo = iTbLmtrepairWorkdetailService.selectTopOneByLmtNumberAndRepairChar(tbLocomotiveVo.getLmtNumber(), "二级修");
                if (tbLmtrepairWorkdetailVo != null) {
                    if (tbLmtrepairWorkdetailVo.getStartTime() != null) {
                        int dayNum = DateUtils.differentDaysByMillisecond(tbLmtrepairWorkdetailVo.getStartTime(), nowDate);
                        System.out.println(dayNum);
                        //为当前车辆新建计划（添加到计划中）
                        PageQuery pageQuery = new PageQuery();
                        pageQuery.setPageNum(1);
                        pageQuery.setPageSize(1);
                        TableDataInfo<TbLocomotiveVo> tbLocomotiveVoTable = tbLocomotiveService.lmtListByStatus(bo, pageQuery);
                        if (tbLocomotiveVoTable != null) {
                            List<TbLocomotiveVo> rows = tbLocomotiveVoTable.getRows();
                            if (rows != null && rows.size() > 0) {
                                TbRepairplanlistBo repairplanlistBo = BeanUtil.toBean(rows.get(0), TbRepairplanlistBo.class);
                                repairplanlistBo.setId(null);
                                repairplanlistBo.setRepairType("二级修");
                                repairplanlistBos.add(repairplanlistBo);
                            }
                        }
                    }
                }
            }
            if (repairplanlistBos != null && repairplanlistBos.size() > 0) {
                TbRepairplanBo repairplanBo = new TbRepairplanBo();
                repairplanBo.setStatus("预计划");
                repairplanBo.setPlanName(DateUtils.getDate() + " " + type.getLmtType() + " 系统生成计划");
                repairplanBo.setPlanDate(nowDate);
                repairplanBo.setRepairplanlistVos(repairplanlistBos);
            }
        }
    }

    /**
     * 录入轮径信息
     */
    public void tongBuWheelDiameter(){
        List<String> lmtrepairWorkdetailIds = tbWheelDiameterMapper.selectAllLmtrepairWorkdetailId();
        List<TbLmtrepairWorkdetailVo> tbLmtrepairWorkdetailVos = iTbLmtrepairWorkdetailService.queryListAndNotIds("轮径", "wheelDiameter1Left1", lmtrepairWorkdetailIds);
        for (TbLmtrepairWorkdetailVo lmtrepairWorkdetailVo : tbLmtrepairWorkdetailVos) {
            List<WheelDiameterDataVo> wheelDiameterDataList = iTbLmtrepairWorkdetailService.getWheelDiameterDataList(lmtrepairWorkdetailVo.getFillData());
            if (wheelDiameterDataList != null && wheelDiameterDataList.size() > 0) {
                TbWheelDiameter tbWheelDiameter = new TbWheelDiameter();
                tbWheelDiameter.setLmtrepairWorkdetailId(lmtrepairWorkdetailVo.getId());
                tbWheelDiameter.setEndTime(lmtrepairWorkdetailVo.getEndTime());
                tbWheelDiameter.setLmtNumber(lmtrepairWorkdetailVo.getLmtNumber());
                tbWheelDiameter.setLmtType(lmtrepairWorkdetailVo.getLmtType());
                tbWheelDiameter.setJsonData(JsonUtils.toJsonString(wheelDiameterDataList));
                tbWheelDiameterMapper.insert(tbWheelDiameter);
            }
        }
    }

    public void test1(){
        List<WheelDiameterDataVo> wheelDiameterDataList = iTbLmtrepairWorkdetailService.getWheelDiameterDataList("{\"date\":1736224924488,\"html_33dgx8fc1\":\"<div style=\\\"text-align:center\\\">\\n\\t1轴<br><1\\n</div>\",\"wheelDiameter3Right1\":\"\",\"wheelDiameter3Right2\":\"\",\"input_61ql2ney\":\"\",\"input_zhmqhzyv2\":\"\",\"work_user3\":\"\",\"html_kzx04v95\":\"<div style=\\\"text-align:center\\\">\\n\\t同转向架轮径差\\n</div>\",\"wheelDiameter3Left2\":\"\",\"input_o26jrjhz\":\"\",\"html_kkmaxg0l\":\"<div>\\n\\t说明：1、同车各车轮轮径差＜4mm；轮径90度测2个数值；内侧距120度测量3个数值，3处差最大值不得大于3mm；2、对轮对弛缓线进行检查，如有异常与踏面或轮缘缺陷等在备注栏内注明。   \\n</div>\",\"html_mzs42eqv1\":\"<div style=\\\"text-align:center\\\">\\n\\t<2\\n</div>\",\"html_j30wh8ng\":\"<div style=\\\"text-align:center\\\">\\n\\t项目\\n</div>\",\"input_3y83ritn\":\"\",\"check_accept_user\":\"\",\"html_gmhheyvo\":\"<div style=\\\"text-align:center\\\">\\n\\t4轴<br><1\\n</div>\",\"html_fwqt23d6\":\"<div style=\\\"text-align:center\\\">\\n\\t内侧距<br>（1353±3）\\n</div>\",\"input_d5py5fco2\":\"\",\"input_kuge58uq1\":\"\",\"html_llmow3v3\":\"<div style=\\\"text-align:center\\\">\\n\\t轮辋厚度<br>（≥23）\\n</div>\",\"html_gmhheyvo2\":\"<div style=\\\"text-align:center\\\">\\n\\t2轴<br><1\\n</div>\",\"input_km7bzbdi\":\"\",\"wheelDiameter1Left1\":\"\",\"input_uu8a4d5n2\":\"\",\"input_zhmqhzyv\":\"\",\"wheelDiameter1Left2\":\"\",\"input_sfwylfjt1\":\"\",\"wheelDiameter3Left1\":\"\",\"html_jmbj80hm\":\"<div style=\\\"text-align:center\\\">\\n\\t右<br>≤0.5\\n</div>\",\"input_6gtytqbq\":\"\",\"input_3y83ritn1\":\"\",\"input_3d12b65l\":\"\",\"html_9kkd4meg2\":\"<div style=\\\"text-align:center\\\">\\n左<br>≤0.5\\n</div>\",\"input_oli3vvtw\":\"\",\"input_kgnb5oid1\":\"\",\"input_o26jrjhz2\":\"\",\"html_mzs42eqv\":\"<div style=\\\"text-align:center\\\">\\n\\t<2\\n</div>\",\"input_5n89y2gs2\":\"\",\"html_e62fm3nn1\":\"<div style=\\\"text-align:center\\\">\\n\\t右<br>≤0.5\\n</div>\",\"input_2du1mz9e2\":\"\",\"inspect_user\":\"admin\",\"input_f18kp7lc1\":\"\",\"html_3xr6ynce\":\"<div style=\\\"text-align:center\\\">\\n\\t轮径\\n</div>\",\"input_vbz8lg56\":\"\",\"wheelDiameter1Right2\":\"\",\"wheelDiameter1Right1\":\"\",\"input_f18kp7lc\":\"\",\"html_33dgx8fc\":\"<div style=\\\"text-align:center\\\">\\n\\t3轴<br><1\\n</div>\",\"input_cl583wja2\":\"\",\"input_5n89y2gs\":\"\",\"html_9kkd4meg\":\"<div style=\\\"text-align:center\\\">\\n左<br>≤0.5\\n</div>\",\"html_2xx5u11p\":\"<div style=\\\"text-align:center\\\">\\n\\t左<br>≤0.5\\n</div>\",\"html_402m7fro\":\"<div style=\\\"text-align:center\\\">\\n\\t距离轮缘顶点15mm处轮缘厚度<br>（≥23）\\n</div>\",\"html_b7qspc95\":\"<div style=\\\"text-align:center\\\">\\nGC270轨道车轮对测量检查表\\n</div>\",\"wheelDiameter2Right2\":\"\",\"html_e62fm3nn\":\"<div style=\\\"text-align:center\\\">\\n\\t右<br>≤0.5\\n</div>\",\"input_d5py5fco\":\"\",\"wheelDiameter4Left2\":\"\",\"wheelDiameter4Left1\":\"\",\"input_km7bzbdi1\":\"\",\"wheelDiameter2Right1\":\"\",\"input_6gtytqbq2\":\"\",\"html_jmbj80hm2\":\"<div style=\\\"text-align:center\\\">\\n\\t右<br>≤0.5\\n</div>\",\"wheelDiameter4Right1\":\"\",\"input_3d12b65l2\":\"\",\"wheelDiameter4Right2\":\"\",\"input_kuge58uq\":\"\",\"input_vbz8lg561\":\"\",\"input_61ql2ney1\":\"\",\"html_w9741wwg\":\"<div style=\\\"text-align:center\\\">\\n\\t备注\\n</div>\",\"input_sfwylfjt\":\"\",\"lmtNumber\":\"20250107-1\",\"input_oli3vvtw1\":\"\",\"input_uu8a4d5n\":\"\",\"html_2xx5u11p1\":\"<div style=\\\"text-align:center\\\">\\n\\t左<br>≤0.5\\n</div>\",\"input_kgnb5oid\":\"\",\"input_2du1mz9e\":\"\",\"wheelDiameter2Left1\":\"\",\"wheelDiameter2Left2\":\"\",\"input_cl583wja\":\"\"}");

    }
    /**
     * 试验台数据同步
     *
     * @throws ParseException
     */
    @Scheduled(cron = "0 55 23 * * ?")
    //@Scheduled(cron = "*/20 * * * * *")
    public void run4() throws JsonProcessingException {
        LocalDate now = null;
        //109分配阀性能实验
        List<McgsFpfz> mcgsFpfzs = imcgsFpfzService.selectListByDate(now);
        //中继阀性能试验
        List<McgsZjfz> mcgsZjfzs = imcgsZjfzService.selectListByDate(now);
        //空气制动阀大阀
        List<McgsXzz> mcgsXzzes = imcgsXzzService.selectListByDate(now);
        //空气制动阀小阀
        List<McgsXzz1> mcgsXzze1s = imcgsXzz1Service.selectListByDate(now);
        //柱塞紧急阀性能
        List<McgsJjf1z> mcgsJjf1zs = imcgsJjf1zService.selectListByDate(now);
        //遮断阀性能试验
        List<McgsZdfz> mcgsZdfzs = iMcgsZdfzService.selectListByDate(now);
        //油压
        List<DrDamperData> drDamperDatas = iDrDamperDataService.selectListByDate(now);
        //油样
        List<OilSampleDetection> oilSampleDetections = iOilSampleDetectionService.selectListByDate(now);
        int size = mcgsFpfzs.size();
        if (size < mcgsZjfzs.size()) {
            size = mcgsZjfzs.size();
        }
        if (size < mcgsXzzes.size()) {
            size = mcgsXzzes.size();
        }
        if (size < mcgsXzze1s.size()) {
            size = mcgsXzze1s.size();
        }
        if (size < mcgsJjf1zs.size()) {
            size = mcgsJjf1zs.size();
        }
        if (size < mcgsZdfzs.size()) {
            size = mcgsZdfzs.size();
        }
        if (size < drDamperDatas.size()) {
            size = drDamperDatas.size();
        }
        if (size < oilSampleDetections.size()) {
            size = oilSampleDetections.size();
        }
        for (int i = 0; i < size; i++) {
            if (i < mcgsFpfzs.size()) {
                //109分配阀性能实验
                mcgsFpfzsUpdate(mcgsFpfzs.get(i));
            }
            if (i < mcgsZjfzs.size()) {
                //中继阀性能试验
                mcgsZjfzsUpdate(mcgsZjfzs.get(i));
            }
            if (i < mcgsXzzes.size()) {
                //空气制动阀大阀
                mcgsXzzesUpdate(mcgsXzzes.get(i));
            }
            if (i < mcgsXzze1s.size()) {
                //空气制动阀小阀
                mcgsXzze1sUpdate(mcgsXzze1s.get(i));
            }
            if (i < mcgsJjf1zs.size()) {
                //柱塞紧急阀性能
                mcgsJjf1zsUpdate(mcgsJjf1zs.get(i));
            }
            if (i < mcgsZdfzs.size()) {
                //遮断阀性能试验
                mcgsZdfzsUpdate(mcgsZdfzs.get(i));
            }
            if (i < drDamperDatas.size()) {
                //遮断阀性能试验
                drDamperDataUpdate(drDamperDatas.get(i));
            }
            if (i < oilSampleDetections.size()) {
                oilSampleDetectionUpdate(oilSampleDetections.get(i));
            }
        }

    }

    private void oilSampleDetectionUpdate(OilSampleDetection oilSampleDetection) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(oilSampleDetection.getDjNo(), "油样");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(oilSampleDetection));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                OilSampleDetectionBo bo = new OilSampleDetectionBo();
                bo.setId(oilSampleDetection.getId());
                bo.setMcgsBy1("1");
                iOilSampleDetectionService.updateByBo(bo);
            }
        }
    }

    private void drDamperDataUpdate(DrDamperData drDamperData) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(drDamperData.getDjNo(), "液压系统");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(drDamperData));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {

                DrDamperDataBo bo = new DrDamperDataBo();
                bo.setId(drDamperData.getId());
                bo.setMcgsBy1("1");
                iDrDamperDataService.updateByBo(bo);
            }
        }
    }

    private void mcgsZdfzsUpdate(McgsZdfz mcgsZdfz) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(mcgsZdfz.getDjNo(), "空气制动阀小阀");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(mcgsZdfz));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                McgsZdfzBo bo = new McgsZdfzBo();
                bo.setId(mcgsZdfz.getId());
                bo.setMcgsBy1("1");
                iMcgsZdfzService.updateByBo(bo);
            }
        }
    }

    private void mcgsJjf1zsUpdate(McgsJjf1z mcgsJjf1z) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(mcgsJjf1z.getDjNo(), "柱塞紧急阀性能");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(mcgsJjf1z));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                McgsJjf1zBo bo = new McgsJjf1zBo();
                bo.setId(mcgsJjf1z.getId());
                bo.setMcgsBy1("1");
                imcgsJjf1zService.updateByBo(bo);
            }
        }
    }

    private void mcgsXzze1sUpdate(McgsXzz1 mcgsXzz1) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(mcgsXzz1.getDjNo(), "空气制动阀小阀");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(mcgsXzz1));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                McgsXzz1Bo bo = new McgsXzz1Bo();
                bo.setId(mcgsXzz1.getId());
                bo.setMcgsBy1("1");
                imcgsXzz1Service.updateByBo(bo);
            }
        }
    }

    //空气制动阀大阀
    private void mcgsXzzesUpdate(McgsXzz mcgsXzz) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(mcgsXzz.getDjNo(), "空气制动阀大阀");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(mcgsXzz));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                McgsXzzBo bo = new McgsXzzBo();
                bo.setId(mcgsXzz.getId());
                bo.setMcgsBy1("1");
                imcgsXzzService.updateByBo(bo);
            }
        }
    }

    private void mcgsZjfzsUpdate(McgsZjfz mcgsZjfz) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(mcgsZjfz.getDjNo(), "中继阀性能试验");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(mcgsZjfz));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                McgsZjfzBo bo = new McgsZjfzBo();
                bo.setId(mcgsZjfz.getId());
                bo.setMcgsBy1("1");
                imcgsZjfzService.updateByBo(bo);
            }
        }
    }

    ObjectMapper mapper = new ObjectMapper();

    //109分配阀性能实验
    private void mcgsFpfzsUpdate(McgsFpfz mcgsFpfz) throws JsonProcessingException {
        TbLmtrepairWorkdetail tbLmtrepairWorkdetail = tbLmtrepairWorkdetailMapper.selectByLmtNumberAndCategory(mcgsFpfz.getDjNo(), "109分配阀性能实验");
        if (tbLmtrepairWorkdetail != null) {
            TbLmtrepairWorkdetail tbLmtrepairWorkdetail1 = new TbLmtrepairWorkdetail();
            tbLmtrepairWorkdetail1.setId(tbLmtrepairWorkdetail.getId());
            tbLmtrepairWorkdetail1.setFillData(mapper.writeValueAsString(mcgsFpfz));
            int i = tbLmtrepairWorkdetailMapper.updateById(tbLmtrepairWorkdetail1);
            if (i != 0) {
                McgsFpfzBo bo = new McgsFpfzBo();
                bo.setId(mcgsFpfz.getId());
                bo.setMcgsBy1("1");
                imcgsFpfzService.updateByBo(bo);
            }
        }
    }


}
